<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:sa="http://www.thymeleaf.org/extras/sa-token">

<head th:replace="index::head">
</head>

<body>
    <!-- 导航栏 -->
    <ul class="layui-nav" th:replace="index::nav">

    </ul>
    <div class="layui-container">
        <div class="layui-row">
            <div class="layui-col-xs2" th:replace="index::snav">
            </div>
            <div class="layui-col-xs10">
                <div class="layui-container">

                   <form class="layui-form" action="" lay-filter="testform">
                    <h1>编辑产品</h1>
                    <hr>
                    <input type="hidden" name="id" th:value="${product.id}">
                    <div class="layui-form-item">
                         <label class="layui-form-label">产品名称</label>
                         <div class="layui-input-block">
                           <input type="text" name="name" th:value="${product.name}" required  lay-verify="required" placeholder="请输入产品名称" autocomplete="off" class="layui-input">
                         </div>
                    </div>
                    <div class="layui-form-item">
                         <label class="layui-form-label">价格</label>
                         <div class="layui-input-block">
                           <input type="text" name="price" th:value="${product.price}" required  lay-verify="required" placeholder="请输入价格" autocomplete="off" class="layui-input">
                         </div>
                    </div>
                    <div class="layui-form-item">
                         <label class="layui-form-label">库存</label>
                         <div class="layui-input-block">
                           <input type="text" name="stock" th:value="${product.stock}" required  lay-verify="required" placeholder="请输入库存" autocomplete="off" class="layui-input">
                         </div>
                    </div>
                    <div class="layui-form-item">
                         <label class="layui-form-label">描述</label>
                         <div class="layui-input-block">
                           <input type="text" name="description" th:value="${product.description}" required  lay-verify="required" placeholder="请输入描述" autocomplete="off" class="layui-input">
                         </div>
                    </div>
                    <div class="layui-form-item">
                         <label class="layui-form-label">图片</label>
                         <div class="layui-input-block">
                           <input type="text" name="imgUrl" th:value="${product.imgUrl}"  placeholder="请输入图片" autocomplete="off" class="layui-input">
                         </div>
                    </div>
                     <div class="layui-form-item">
                       <div class="layui-input-block">
                         <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                         <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                       </div>
                     </div>
                   </form>
                </div>
            </div>
        </div>
    </div>

</body>
<script>
    layui.use(['layer'], function(args){
      var layer = layui.layer;
      var form = layui.form;
      form.on('submit(formDemo)', function(data){
        //   layer.msg(JSON.stringify(data.field));
        $.post('/product',data.field,function(data){
            if(data.code===200){
                layer.msg('修改成功！'); 
                setTimeout(() => {
                    window.location.href="/product"
                }, 1300);
            }else{
                layer.msg(data.msg); 
            }
        })
          return false;
      });
    }); 
</script>
</html>